<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>系统登录</title>
    <!-- Bootstrap 5.1.3 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .login-container {
            background: linear-gradient(135deg, #6B8DD6 0%, #8E37D7 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
        }
        .card-login {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
            transition: all 0.3s ease;
        }
        .form-control:focus {
            border-color: #8E37D7;
            box-shadow: 0 0 0 0.25rem rgba(142, 55, 215, 0.25);
        }
        .btn-purple {
            background: #8E37D7;
            color: white;
            padding: 12px 30px;
        }
        .btn-purple:hover {
            background: #6B8DD6;
        }
        .switch-text {
            color: #6c757d;
            cursor: pointer;
            transition: color 0.3s;
        }
        .switch-text:hover {
            color: #8E37D7;
        }
    </style>
</head>
<body>
<div class="container-fluid login-container">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-6 col-lg-4">
                <div class="card card-login p-4">
                    <div th:if="${errorMessage}" class="alert alert-danger" th:text="${errorMessage}"></div>
                    <!-- 登录表单 -->
                    <form id="loginForm" class="active-form" action="/api/user/login" method="post">
                        <h3 class="text-center mb-4">用户登录</h3>
                        <div class="mb-3">
                            <label class="form-label">邮箱</label>
                            <input type="email" name="email" class="form-control" placeholder="请输入邮箱" required>
                        </div>
                        <div class="mb-4">
                            <label class="form-label">密码</label>
                            <input type="password" name="password" class="form-control" placeholder="请输入密码" required>
                        </div>
                        <button type="submit" class="btn btn-purple w-100">立即登录</button>
                        <div class="text-center mt-3">
                            <span class="switch-text" onclick="toggleForm('register')">没有账号？立即注册</span>
                        </div>
                    </form>

                    <!-- 注册表单 -->
                    <form id="registerForm" class="d-none" action="/api/user/register" method="post">
                        <h3 class="text-center mb-4">用户注册</h3>
                        <div class="mb-3">
                            <label class="form-label">用户名</label>
                            <input type="text" name="username" class="form-control" placeholder="请输入用户名" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">密码</label>
                            <input type="password" name="password" id="password" class="form-control" placeholder="请输入密码" required>
                        </div>
                        <div class="mb-4">
                            <label class="form-label">确认密码</label>
                            <input type="password" id="confirm_password" class="form-control" placeholder="请再次输入密码" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">邮箱</label>
                            <input type="email" name="email" class="form-control" placeholder="请输入邮箱" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">电话号码</label>
                            <input type="tel" name="phone" class="form-control" placeholder="请输入电话号码" required>
                        </div>
                        <button type="submit" class="btn btn-purple w-100">立即注册</button>
                        <div class="text-center mt-3">
                            <span class="switch-text" onclick="toggleForm('login')">已有账号？立即登录</span>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
    function toggleForm(formType) {
        const loginForm = document.getElementById('loginForm');
        const registerForm = document.getElementById('registerForm');

        if(formType === 'register') {
            loginForm.classList.remove('active-form');
            loginForm.classList.add('d-none');
            registerForm.classList.remove('d-none');
            registerForm.classList.add('active-form');
        } else {
            registerForm.classList.remove('active-form');
            registerForm.classList.add('d-none');
            loginForm.classList.remove('d-none');
            loginForm.classList.add('active-form');
        }
    }

    document.getElementById('registerForm').addEventListener('submit', function(e) {
        const password = document.getElementById('password').value;
        const confirmPassword = document.getElementById('confirm_password').value;

        if (password !== confirmPassword) {
            alert('两次密码输入不一致！');
            e.preventDefault();
        }
    });
</script>
</body>
</html>